<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>404</title>
</head>
<body>




<link rel="stylesheet" href="{$cssUrl}table.css">
<table>
    <tr>
        <td>序号</td>
        <td>职位</td>
        <td>权限</td>
        <td>操作</td>
    </tr>
    {foreach from=$grade item="val" key="key"}
    <tr>
        <form action="{$url}auth/change" method="post">
            <td>{$key}</td>
            <td>{$val.gName}</td>
            <td>
                {foreach from=$allow item='all'}
                {if $all.gID==$val.gID}
                {$all.name}
                {/if}
                {/foreach}
            </td>
            <td>
                {if $val.gName!='超级管理员'}
                <a href="#" class="take">分配</a><input type="hidden" value="{$val.gID}">
                {else}
                不可更改
                {/if}

            </td>
        </form>
    </tr>
    {/foreach}
</table>
<script src="{$jsUrl}jquery.js"></script>
<script src="{$jsUrl}layer/layer.js"></script>
<script>
    {literal}
    $(document).ready(function(){
        $('.take').click(function(){
            var gID = $(this).next().val();
            //console.log(gName);
            layer.open({
                type:2,
                area:['500px','300px'],
                title:'分配',
                shade:0.6,
                anim:2,
            {/literal}
            content: '{$url}auth/take/'+gID,
                {literal}
            btn:['submit'],
                cancel:function(){
                //右上角关闭回调
            },
            yes:function(index){
                var arr = document.getElementById("layui-layer-iframe" + index).contentWindow.document.getElementById("have").childNodes;
                //console.log(name);
                name=JSON.stringify(takes(arr));
                console.log(name);
                $.ajax({
                {/literal}
                url:'{$url}auth/changeAuth',
                    {literal}
                type:'POST', //GET
                    async:true,    //或false,是否异步
                    timeout:5000,    //超时时间
                    data:{'name':name,'gID':gID},
                dataType:'text',    //返回的数据格式：json/xml/html/script/jsonp/text
                    success:function(data){
                    if(data==1100){
                        layer.msg('修改成功');
                        setTimeout(function(){
                            self.location.reload();//页面刷新
                        },1000);
                    }else {
                        alert(data);
                    }
                },
                error:function(){
                    console.log('错误')
                }
            });
                layer.close();

            }

        })
        });
        function takes(arr){
            var arrs = new Array();
            for(var i=0;i<arr.length;i++){
                if(arr[i].nodeName == 'OPTION'){
                    arrs.push(arr[i]);
                }
            }
            //console.log(arrs);
            var narr=new Array();
            $(arrs).each(function(){
                narr.push($(this).val());
            });
            return narr;
        }
    })
    {/literal}
</script>







</body>
</html>